package com.example.demotest;

import com.example.demotest.service.GreatService;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

/**
 * @version 1.0.0
 * @className: TestFunction
 * @description:
 * @author: zhangjunfa
 * @date: 2023/4/25 9:27
 */
public class TestFunction {
    private static GreatService greatService = new GreatService();
    private static Map<String, Function<String, String>> greatType = new HashMap<>();

    static {
        greatType.put("红包", resourceId -> greatService.redPaper(resourceId));
        greatType.put("购物券", resourceId -> greatService.shopping(resourceId));
        greatType.put("vip会员", resourceId -> greatService.vip(resourceId));
    }

    public static String getResult(String resourceType, String resourceId) {
        // Controller根据 优惠券类型resourceType、编码resourceId 去查询 发放方式grantType
        Function<String, String> result = greatType.get(resourceType);
        if (result != null) {
            // 传入 resourceId 执行这段表达式获得String型的grantType
            return result.apply(resourceId);
        }
        return "查询不到该优惠券的发放方式";
    }

    public static void main(String[] args) {
        System.out.println(getResult("红包","54571634979"));
    }

}
